
cd "C:\Users\jmunoz\Dropbox\01 - Recerca\replication_sweden\Final paper WP\Replication WP"

**----------------------------------------**
**-----Tables & Figures main text---------**
**----------------------------------------**

*Figure 1 main text

use "03 - Working data\marital_class.dta", clear

keep eligible voted year gender
collapse (sum) eligible voted, by(year gender)
gen turnout=voted/eligible*100

twoway (line turnout year if gender == 1, cmissing(n) lcolor(black) lpattern(solid)) ///
       (line turnout year if gender == 2, cmissing(n) lcolor(gs8) lpattern(solid)) ///
	   (scatter turnout year if gender == 1, mcolor(black) msymbol(oh)) ///
       (scatter turnout year if gender == 2, mcolor(gs8) msymbol(oh)), ///
       ylabel(40(10)90) xlabel(1921 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960) legend(order(1 "A.Male" 2 "B.Female")) ///
       xtitle("Years") ytitle("") scheme(plotplain)
graph export "04 - Tables and figures\fig1.eps", replace

*Figure 3 main text

use "03 - Working data\marital_class.dta", clear

keep hisclass7_reorder marital year voted eligible
collapse (sum) eligible voted, by(year marital hisclass7_reorder)
gen turnout=voted/eligible*100

*We create empty observations for 1932
drop if year==1932
expand 2 if year == 1928, gen(newobs)
replace year=1932 if newobs==1
replace eligible=. if newobs==1
replace voted=. if newobs==1
replace turnout=. if newobs==1
sort year marital hisclass7_reorder
drop newobs

twoway (line turnout year if marital == 1, cmissing(n)  lpattern(solid)) ///
       (line turnout year if marital == 2, cmissing(n) lpattern(dash)) ///
		(line turnout year if marital == 3, cmissing(n)  lpattern(dash_dot)) ///
       (line turnout year if marital == 4, cmissing(n)  lpattern(solid)) ///
	   (scatter turnout year if marital == 1, mcolor(black) msymbol(.) msize(vsmall)) ///
       (scatter turnout year if marital == 2, mcolor(gs10) msymbol(.) msize(vsmall)) ///
		(scatter turnout year if marital == 3, mcolor(sky)  msymbol(.) msize(vsmall)) ///
       (scatter turnout year if marital == 4,  mcolor(turquoise) msymbol(.) msize(vsmall)), ///
	   by(hisclass7_reorder, cols(4) note("") ixaxes) ///
       ylabel(10(10)100) xlabel(1921 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960, angle(90)) ///
	   legend(order(1 "A.Male" 4 "B. Female Married" 3 "C. Female, F.Employed " 2 "Female, Unmarried, Not f. Employed") position(12) cols(4)) xtitle("") ytitle("") scheme(plotplainblind)	   
	   
graph export "04 - Tables and figures\fig3.eps", replace
	

*Table 2 main text 	
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital i.class_3 c.year_c [fw= eligible], cluster(id)
est store m1

reg turnout b4.marital##c.year_c i.class_3 [fw= eligible], cluster(id)
est store m2

reg turnout b4.marital##i.class_3 c.year_c [fw= eligible], cluster(id)
est store m3

esttab m1 m2 m3 using "04 - Tables and figures\table2.rtf",  noomitted  nobaselevels label se(%9.2f) b(%9.2f) stats(N r2) compress replace

*Figure 4 main text
use "03 - Working data\marital_class.dta", clear
reg turnout b4.marital##i.year i.class_3 [fw= eligible], cluster(id)
margins, over(year marital)
marginsplot, xtitle("Election", size(small)) ytitle("Predicted Turnout", size(small)) xlabel(, labsize(vsmall)) ylabel(, labsize(vsmall)) title("") legend(pos(6)  col(4)) scheme(plotplainblind)

graph export "04 - Tables and figures\fig4.eps", replace

*Figure 5 main text
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital##i.class_3 c.year_c [fw= eligible], cluster(id)
margins, over(class marital)
marginsplot, xtitle("", size(small)) ytitle("Predicted Turnout", size(small)) xlabel(, labsize(vsmall)) ylabel(, labsize(vsmall)) title("") legend(pos(6)  col(4)) scheme(plotplainblind)

graph export "04 - Tables and figures\fig5.eps", replace

*figure 6 main text
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital##i.class_3##i.year [fw= eligible], cluster(id)
margins, over(year class marital)
marginsplot, by(class) xtitle("", size(small)) ytitle("Predicted Turnout", size(small)) xlabel(, labsize(vsmall)) ylabel(, labsize(vsmall)) title("") legend(pos(6)  col(4)) scheme(plotplainblind)

graph export "04 - Tables and figures\fig6.eps", replace

*Table 3 main text
use "03 - Working data\marital_class_lan.dta", clear

reg Turnout_pct b1.marital i.class_3 i.year  i.stad i.lan_num [fw= Eligible] if year<=1928, cluster( id)
est store ms1
reg Turnout_pct b1.marital##i.class_3 i.year  i.stad i.lan_num [fw= Eligible] if year<=1928, cluster( id)
est store ms2
reg Turnout_pct b1.marital##i.stad b1.marital##i.class_3 i.year   i.lan_num [fw= Eligible] if year<=1928, cluster( id)
est store ms3

esttab ms1 ms2 ms3 using "04 - Tables and figures\table3.rtf", drop(*.lan_num *.year) noomitted  nobaselevels label se(%9.2f) b(%9.2f) stats(N r2) compress replace

*Figure 7 main text
use "03 - Working data\marital_class_lan.dta", clear

reg Turnout_pct b1.marital##i.stad i.hisclass7_n i.year   i.lan_num [fw= Eligible] if year<=1928, cluster( id)
margins,  over(stad marital)
marginsplot, title("") ytitle("Predicted Turnout", size(small)) scheme(plotplainblind)

graph export "04 - Tables and figures\fig7.eps"

*Figure 8 main text
use "03 - Working data\sample48_56.dta", clear

reg turnout b2.marital##b2.habitat##i.generation##i.gender_n i.year [fw=Eligible] 
margins,  at(generation=(1 2 3 4) gender=(1 2) )
marginsplot, ytitle("Predicted turnout")  xtitle("Generation") title("Panel A: Gender turnout gap across generations", justification(left) position(11) ring(5)) legend(position(6) cols(2)) fxsize(50) name(panela, replace) scheme(plotplainblind)

margins, at(generation=(1 2 3 4) habitat=(1 2) gender_n=(1 2))
marginsplot, by(gender_n) byopt(title("Panel B: Urban-rural gap across generations",  justification(left) position(11) ring(1))) ytitle("") xtitle("") plot( , label("Rural" "Urban")) legend(cols(2)) xlabel(, alternate)  name(panelb, replace) scheme(plotplainblind)

margins, at(generation=(1 2 3 4) marital=(1 2) habitat=(1) gender_n=(1 2))
marginsplot, by(gender_n) byopt(title("Panel C: Marriage and turnout in rural areas",  justification(left) position(11) ring(1))) ytitle("") xtitle("") plot( , label("Unmarried" "Married")) legend(cols(2)) xlabel(, alternate) name(panelc, replace) scheme(plotplainblind)

margins, at(generation=(1 2 3 4) marital=(1 2) habitat=(2) gender_n=(1 2))
marginsplot, by(gender_n) byopt(title("Panel D: Marriage and turnout in urban areas",  justification(left) position(11) ring(1))) ytitle("") xtitle("") plot( , label("Unmarried" "Married")) legend(cols(2)) xlabel(, alternate) name(paneld, replace) scheme(plotplainblind)

graph combine panela panelb panelc paneld, ycommon scheme(plotplainblind)

graph export "04 - Tables and figures\fig8.eps"


**----------------------------------------**
**------Tables & Figures appendix---------**
**----------------------------------------**

**--------------------------------**
*-----Appendix B HISCLASS 7-------**
**--------------------------------**

*Table B1 appendix 
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital i.hisclass7 c.year_c [fw= eligible], cluster(id)
est store m1

reg turnout b4.marital##c.year_c i.hisclass7  [fw= eligible], cluster(id)
est store m2

reg turnout b4.marital##i.hisclass7 c.year_c [fw= eligible], cluster(id)
est store m3

esttab m1 m2 m3 using "04 - Tables and figures\tableB1_app.rtf",  noomitted  nobaselevels label se(%9.2f) b(%9.2f) stats(N r2) compress replace
 
 *Table B2 appendix
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital##i.class_3##c.year_c [fw= eligible], cluster(id)
est store triple
esttab triple using "04 - Tables and figures\tableB2_app.rtf",  noomitted  nobaselevels label se(%9.2f) b(%9.2f) stats(N r2) compress replace

*Figure B1 Appendix
use "03 - Working data\marital_class.dta", clear

reg turnout b4.marital##i.hisclass7##i.year [fw= eligible], cluster(id)
margins, over(year hisclass7 marital) force
marginsplot, by(hisclass7) xtitle("", size(small)) ytitle("Predicted Turnout", size(small)) xlabel(, labsize(vsmall)) ylabel(, labsize(vsmall)) byopts(title("")) legend(pos(6)  col(4)) scheme(plotplainblind)
graph export "04 - Tables and figures\figB1_app.eps", replace

*Figure B2 appendix
use "03 - Working data\marital_class.dta", clear

reg turnout i.gender##i.hisclass7##i.year [fw= eligible], cluster(id)
margins, over(year hisclass7 gender) force
marginsplot, by(gender) xtitle("", size(small)) ytitle("Predicted Turnout", size(small)) xlabel(, labsize(vsmall)) ylabel(, labsize(vsmall)) byopts(title("")) legend(pos(6)  col(4)) scheme(plotplainblind)
graph export "04 - Tables and figures\figB2_app.eps", replace

**--------------------------------**
*-----Appendix D Age & Cohort-----**
**--------------------------------**

*Table D1 appendix
use "03 - Working data\sample48_56.dta", clear

reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==1 & year==1948 [fw=Eligible]
est store male48
reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==2 & year==1948 [fw=Eligible]
est store female48
reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==1 & year==1952 [fw=Eligible]
est store male52
reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==2 & year==1952 [fw=Eligible]
est store female52
reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==1 & year==1956 [fw=Eligible]
est store male56
reg turnout b2.marital_n##b2.habitat_n c.Age##c.Age if gender_n==2 & year==1956 [fw=Eligible]
est store female56
esttab male48 female48 male52 female52 male56 female56 using "04 - Tables and figures\tableD1_app.rtf", se par stats(r2 N) b(%9.2f) noomitted nobase mtitles replace

*Table D2 appendix
use "03 - Working data\sample48_56.dta", clear

reg turnout b2.generation b2.habitat b2.marital i.year [fw=Eligible] if gender_n==1
est store male1
reg turnout b2.generation b2.habitat b2.marital i.year [fw=Eligible] if gender_n==2
est store female1
reg turnout  b2.generation b2.marital##b2.habitat i.year [fw=Eligible] if gender_n==1
est store male2
reg turnout b2.generation b2.marital##b2.habitat i.year [fw=Eligible] if gender_n==2
est store female2
reg turnout  b2.habitat##b2.generation b2.marital i.year [fw=Eligible] if gender_n==1
est store male3
reg turnout b2.habitat##b2.generation b2.marital i.year [fw=Eligible] if gender_n==2
est store female3

esttab male1 female1 male2 female2 male3 female3 using "04 - Tables and figures\tableD2_app.rtf", se par stats(r2 N) b(%9.2f) noomitted nobase mtitles replace 


**--------------------------------**
*------Appendix E 1960 survey-----**
**--------------------------------**

*Figure E1 Gender gap by generation appendix
use "03 - Working data\1960_election_survey.dta", clear

reg turnout1960  i.gender##i.cohort
margins, dydx(gender) over(cohort)
marginsplot, yline(0) ytitle("Gender turnout gap") xtitle("Generation") title("") scheme(plotplainblind)
graph export "04 - Tables and figures\figE1_appendix.eps", replace

*Figure E2 Turnout appendix
use "03 - Working data\1960_election_survey.dta", clear

reg turnout1960  i.gender##i.rural##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) rural=(0 1))
marginsplot, by(gender) name(trnt_rural, replace) byopt(title("Urban-rural")) ytitle("") xtitle("") plot( , label("Urban" "Rural")) legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg turnout1960  i.gender##i.marital##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) marital=(1 4))
marginsplot, by(gender) name(trnt_marital, replace) byopt(title("Marital status")) ytitle("") xtitle("") legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg turnout1960  i.gender##i.occupation##i.cohort
margins, at(cohort=(1 2 3 4) occupation=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(trnt_occupation, replace) byopt(title("Occupation")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

reg turnout1960  i.gender##i.class3##i.cohort
margins, at(cohort=(1 2 3 4) class3=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(trnt_class, replace) byopt(title("Class")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

graph combine trnt_rural trnt_marital trnt_occupation trnt_class , scheme(plotplainblind)
graph export "04 - Tables and figures\figE2_appendix.eps", replace

*Figure E3 Political interest appendix
use "03 - Working data\1960_election_survey.dta", clear

reg polint  i.gender##i.rural##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) rural=(0 1))
marginsplot, by(gender) name(polint_rural, replace) byopt(title("Urban-rural")) ytitle("") xtitle("") plot( , label("Urban" "Rural")) legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg polint  i.gender##i.marital##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) marital=(1 4))
marginsplot, by(gender) name(polint_marital, replace) byopt(title("Marital status")) ytitle("") xtitle("") legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg polint  i.gender##i.occupation##i.cohort
margins, at(cohort=(1 2 3 4) occupation=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(polint_occupation, replace) byopt(title("Occupation")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)


reg polint  i.gender##i.class3##i.cohort
margins, at(cohort=(1 2 3 4) class3=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(polint_class, replace) byopt(title("Class")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

graph combine polint_rural polint_marital polint_occupation polint_class, scheme(plotplainblind)
graph export "04 - Tables and figures\figE3_appendix.eps", replace

*Figure E4 Political knowledge appendix
use "03 - Working data\1960_election_survey.dta", clear

reg polknow  i.gender##i.rural##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) rural=(0 1))
marginsplot, by(gender) name(polknow_rural, replace) byopt(title("Urban-rural")) ytitle("") xtitle("") plot( , label("Urban" "Rural")) legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg polknow  i.gender##i.marital##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) marital=(1 4))
marginsplot, by(gender) name(polknow_marital, replace) byopt(title("Marital status")) ytitle("") xtitle("") legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg polknow  i.gender##i.occupation##i.cohort
margins, at(cohort=(1 2 3 4) occupation=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(polknow_occupation, replace) byopt(title("Occupation")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

reg polknow  i.gender##i.class3##i.cohort
margins, at(cohort=(1 2 3 4) class3=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(polknow_class, replace) byopt(title("Class")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

graph combine polknow_rural polknow_marital polknow_occupation polknow_class, scheme(plotplainblind)
graph export "04 - Tables and figures\figE4_appendix.eps", replace

*Figure E5 Political discussion appendix
use "03 - Working data\1960_election_survey.dta", clear

reg poldiscuss  i.gender##i.rural##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) rural=(0 1))
marginsplot, by(gender) name(poldiscuss_rural, replace) byopt(title("Urban-rural")) ytitle("") xtitle("") plot( , label("Urban" "Rural")) legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)
 
reg poldiscuss  i.gender##i.marital##i.cohort
margins, at(gender=(1 2)  cohort=(1 2 3 4) marital=(1 4))
marginsplot, by(gender) name(poldiscuss_marital, replace) byopt(title("Marital status")) ytitle("") xtitle("") legend(cols(2)) xlabel(, alternate) scheme(plotplainblind)

reg poldiscuss  i.gender##i.occupation##i.cohort
margins, at(cohort=(1 2 3 4) occupation=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(poldiscuss_occupation, replace) byopt(title("Occupation")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

reg poldiscuss  i.gender##i.class3##i.cohort
margins, at(cohort=(1 2 3 4) class3=(1 2 3) gender=(1 2)  )
marginsplot, by(gender) name(poldiscuss_class, replace) byopt(title("Class")) ytitle("") xtitle("") legend(cols(3)) xlabel(, alternate) scheme(plotplainblind)

graph combine poldiscuss_rural poldiscuss_marital poldiscuss_occupation poldiscuss_class, scheme(plotplainblind)
graph export "04 - Tables and figures\figE5_appendix.eps", replace

**--------------------------------**
*------Appendix F Unions----------**
**--------------------------------**

*Table F1 appendix
use "03 - Working data\uniondata.dta", clear

reg Turnout_Rate i.gender_n i.class3 i.Year [fw=Eligible]
est store m1
reg Turnout_Rate i.gender_n i.class3 c.uniond i.Year [fw=Eligible]
est store m2
reg Turnout_Rate i.gender_n##c.uniond i.class3  i.Year [fw=Eligible]
est store m3
reg Turnout_Rate i.gender_n##c.uniond##i.class3  i.Year [fw=Eligible]
est store m4
reg Turnout_Rate i.gender_n##c.uniond##i.class3  i.Year i.Lan [fw=Eligible]
est store m5

esttab m1 m2 m3 m4 m5 using "04 - Tables and figures\tabF1_appendix.rtf", se par stats(r2 N) b(%9.2f) noomitted nobase mtitles drop(*Lan*) replace 

*Figure F1 appendix
use "03 - Working data\uniondata.dta", clear

reg Turnout_Rate i.gender##c.uniond##i.class3  i.Year i.Lan [fw=Eligible]
margins, at( uniond=(0(0.05)0.25) class3=(1 2 3) gender=(1 2 3 4)  )
marginsplot, by(gender) byopt(title("")) ytitle("Predicted turnout") xtitle("Union density") legend(cols(3))  scheme(plotplainblind)

graph export "04 - Tables and figures\figF1_appendix.eps", replace

*Table F2 appendix
use "03 - Working data\1960_election_survey.dta", clear

tab union gender, col nofreq 
tab party gender, col nofreq 
tab turnout1960 gender, col nofreq 

*Table F3 appendix
use "03 - Working data\1960_election_survey.dta", clear

reg turnout1960  i.gender##b2.cohort  i.rural  i.marital 
est store m1
reg turnout1960  i.gender##b2.cohort  i.rural  i.marital  party union
est store m2
reg turnout1960  i.gender##b2.cohort  i.rural  i.marital party union
est store m3
reg turnout1960  i.gender##b2.cohort  i.rural  i.marital i.gender##party i.gender##union 
est store m4

esttab m1 m2 m3 m4 using "04 - Tables and figures\tabF3_appendix.rtf", se par stats(r2 N) b(%9.2f) noomitted nobase mtitles replace 






